package com.yxhl.zoume.core.func.appraisal.presenter;

import android.content.Context;

import com.yxhl.zoume.common.presenter.BasePresenter;
import com.yxhl.zoume.common.ui.view.BaseView;
import com.yxhl.zoume.core.func.appraisal.view.AppraisalLabelView;
import com.yxhl.zoume.data.http.rest.param.appraisal.AppraisalLabelParam;
import com.yxhl.zoume.data.http.rest.response.appraisal.AppraisalLabelResponse;
import com.yxhl.zoume.domain.interactor.ZMSubscriber;
import com.yxhl.zoume.domain.interactor.appraisal.AppraisalLabelUseCase;

import javax.inject.Inject;

/**
 * Created by vhawk on 16/9/18.
 */

public class AppraisalLabelPresenter extends BasePresenter {

    @Inject
    AppraisalLabelUseCase useCase;
    private AppraisalLabelView view;

    @Inject
    public AppraisalLabelPresenter(Context context) {
        super(context);
    }


    @Override
    public void attachView(BaseView view) {
        this.view = (AppraisalLabelView) view;
    }

    /**
     * 获取评价标签
     */
    public void fetchAppraisalLabel() {
        AppraisalLabelParam param = new AppraisalLabelParam();
        param.setMobile(getMobile())
                .setToken(getToken());

        useCase.execute(param,new ZMSubscriber<AppraisalLabelResponse>() {
            @Override
            public void onNext(AppraisalLabelResponse response) {
                super.onNext(response);
                if (response.isSucc()) {
                    view.handleFetchLabelSucceed(response.getLabels());
                } else {
                    view.handleFetchLabelFailure(response.getResultMessage());
                }
            }


            @Override
            public void onError(Throwable e) {
                super.onError(e);
                view.handleFetchLabelError();
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        useCase.unsubscribe();
    }
}
